<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="applicable-device" content="pc">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="keywords" content="">
		<meta name="description" content="">

		<link rel="icon" href="" />
		<link rel="stylesheet" href="/static/index/css/reset.css" />

		<link rel="stylesheet" href="/static/index/lib/bootstrap.min.css" />

		<link rel="stylesheet" href="/static/index/css/common.css" />
		<link rel="stylesheet" href="/static/index/css/home.css" />
		<link rel="stylesheet" href="/static/index/css/users.css" />

		<link rel="stylesheet" href="/static/index/lib/pick-pcc.css" />

		<script src="/static/index/lib/jquery-2.1.4.js"></script>
		<script src="/static/index/layer/layer.js"></script>
		<script type="text/javascript" src="/static/index/lib/template.js"></script>

		<style type="text/css">
			.pick-area {
				background: transparent;
			}
			
			.pick-show {
				background: transparent;
				height: 40px;
				line-height: 40px;
				border: 1px solid #dedede;
			}
			
			.pick-show span {
				margin-top: 7px;
			}
			
			.pick-show em.pick-arrow {
				top: 16px;
			}
		</style>
		<script>
			var _hmt = _hmt || [];
			(function() {
			  var hm = document.createElement("script");
			  hm.src = "https://hm.baidu.com/hm.js?8b340ebdd740974de9d621b14ab09b43";
			  var s = document.getElementsByTagName("script")[0]; 
			  s.parentNode.insertBefore(hm, s);
			})();
		</script>
	</head>

	<body>
		{include file="public/push"}
		{include file="public/usersHeader"}
		
		
		<div class="widthFullScreen">
			<div class="wdSafe user_body clearfix">
				{include file="public/usersLeftNav"}
				<!-- left over -->
				<div class="pull-right right_wrap">

					<div id="stateDailog" class="alert alert-danger alert-dismissible" role="alert">
					    <strong>提示!</strong> 您还没有完成实名认证，请尽快完成是实名认证！
					</div>

					<div class="nav_common border-top">
						<ol class="breadcrumb pull-left">
							<li>
								<a href="javascript:;">用户中心</a>
							</li>
							<li>
								<a href="javascript:;">我的账户</a>
							</li>
							<li class="active">实名认证</li>
						</ol>
					</div>

					<div id="formHtml"></div>
					<script id="formScript" type="text/html">
						
						<div class="comUser_wrap">
							<div class="form-horizontal">
								<div class="form-group">
									<label for="two" class="col-sm-2 control-label">
										<span class="colorRed">*</span>&nbsp;&nbsp;公司名称
									</label>
									<div class="col-sm-10">
										<input type="text" class="form-control ipt_styleSub" name="name" autocomplete='text' placeholder="请输入公司名称" id="name" value="{{securities.name}}" />
										<span class="help-block">请如实填写公司名称，一旦审核通过，公司名称将不能修改</span>
									</div>
								</div>

								<div class="form-group">
									<label for="two" class="col-sm-2 control-label">
										<span class="colorRed">*</span>&nbsp;&nbsp;公司地址
									</label>
									<div class="col-sm-10">
										<select class="secelcStyleAddress form-control" name="" id="provenceSelect">
											<option value="" dId="">{{securities.province}}</option>
										</select>
										<select class="secelcStyleAddress form-control" name="" id="citySelect">
											<option value="">{{securities.city}}</option>
										</select>
									</div>
								</div>

								<div class="form-group">
									<label for="two" class="col-sm-2 control-label">
										<span class="colorRed">*</span>&nbsp;&nbsp;详细地址
									</label>
									<div class="col-sm-10">
										<input type="text" class="form-control ipt_styleSub" name="" autocomplete='text' placeholder="请输入公司详细地址" id="address" value="{{securities.address}}" />
									</div>
								</div>
								<div class="form-group">
									<label for="two" class="col-sm-2 control-label">
										<span class="colorRed">*</span>&nbsp;&nbsp;公司规模
									</label>
									<div class="col-sm-10">
										<input type="text" class="form-control ipt_styleSub" name="" autocomplete='text' placeholder="请输入营业执照上的公司规模" id="scale" value="{{securities.scale}}" />
									</div>
								</div>

								<form method="post" id="zhizhiaoForm" enctype="multipart/form-data">
									<div class="form-group">
										<label for="" class="col-sm-2 control-label">
											<span class="colorRed">*</span>&nbsp;&nbsp;营业执照
										</label>
										<div class="col-sm-7">
											<div class="imgWrap_upload">
												<div class="upLoadImg_style">
													<img id="logoPic" src="https://img.qikuai100.com/bg.png" />
													<input type="file" name="file" id="logoIpt" accept="image/*"/>
												</div>
											</div>
										</div>
									</div>
								</form>

								
								<div class="form-group">
									<div class="col-sm-offset-2 col-sm-10">
										<div class="submitBtn" onclick="saveNews()" id="saveNews">保存</div>
									</div>
								</div>
							</div>

						</div>
					</script>

				</div>
				<!-- right over -->
			</div>
		</div>

		<div class="widthFullScreen heightGray"></div>



		{include file="public/footer"}

		<script type="text/javascript" src="/static/index/lib/pick-pcc.min.1.0.2.js"></script>
		<script type="text/javascript" src="/static/index/lib/cityJson.js"></script>
		

		<script type="text/javascript">
			var baseUrl = 'https://api.qikuai100.com/';
			var uid = localStorage.getItem("uid"),
				states = 0, // 审核状态
				strAddress = '选择省/选择市'; // 省市区
			var cityJson = {};

			$(function() {
				/**
			    * 上传营业执照
			    */
			    var uploadingLogo = false;
			    $("#logoIpt").on("change", function() {
			        if (uploadingLogo) {
			            layer.msg("文件正在上传中，请稍候");
			            return false;
			        }
			        var indexLogo = layer.load(1, {shade: false});
			        $.ajax({
			            url: baseUrl + "api/img/upload",
			            type: 'POST',
			            cache: false,
			            data: new FormData($('#zhizhiaoForm')[0]),
			            processData: false,
			            contentType: false,
			            dataType: "json",
			            beforeSend: function() {
			                uploadingLogo = true;
			            },
			            success: function(data) {
			                layer.close(indexLogo);
			                if (data.ret == 0) {
			                    $("#logoPic").attr("src", data.data.url);
			                } else {
			                    layer.msg("上传logo失败");
			                }
			                uploadingLogo = false;
			            }
			        });
			    });

				initInfor();
				cityJson = cityFun();
				
			});

			/**
			* 初始化
			* 0=>'未认证', 1=>'审核中',2=>'未通过' 3 审核通过
			*/
			function initInfor(){

				$.ajax({
					type: "POST",
					url: baseUrl + "api/company/info",
					data: {
						"uid": uid
					},
					success: function(result) {
						console.log(result.data);
						// return;
						var dataL = result.data;
						states = dataL.securities.verify_status;
						if(result.ret == 0){
							var formHtml = template('formScript',dataL);
					        document.getElementById('formHtml').innerHTML = formHtml;
					        if(states == 0){
					        	$('#stateDailog').show();
					        }else{
					        	$('#stateDailog').hide();
					        }
							if(states == 1 || states == 3){
								$('#formHtml').find("input").attr("disabled","disabled");
							}else{
								$('#formHtml').find("input").removeAttr("disabled");
							}
							if(dataL.securities.licence_poster){
								$('#logoPic').attr("src", dataL.securities.licence_poster);
							}
							if(dataL.securities.province){
								$('#provenceSelect').attr("disabled","disabled");
								$('#citySelect').attr("disabled","disabled");
							}else{
								
								$('#provenceSelect').removeAttr("disabled");
								$('#citySelect').removeAttr("disabled");
								addressInit();
							}

						}else{
							layer.msg(result.res_info);
						}
					}
				});
			}

			/**
			* 初始化地址
			*/
			function addressInit(){
				var strOne = '';
				for(var i = 0; i < cityJson.data.length; i++){
					strOne += '<option value="'+ cityJson.data[i].name +'" dId="'+ cityJson.data[i].id +'">'+ cityJson.data[i].name +'</option>'; 
				}
				$('#provenceSelect').html(strOne);
			}

			$('#formHtml').on("change", "#provenceSelect", function() {
				var sss = $(this).children('option:selected').attr("dId");
				var jsonCity = [],
					strHtml = '';
				for(var i = 0; i < cityJson.data.length; i++){
					if(sss == cityJson.data[i].id){
						jsonCity = cityJson.data[i].cities;
					}
				}
				for(var i = 0; i < jsonCity.length; i++){
					strHtml += '<option value="'+ jsonCity[i].name +'" dId="'+ jsonCity[i].id +'">'+ jsonCity[i].name +'</option>'; 
				}
				$('#citySelect').html(strHtml);
			});
		
			
			/**
			* 完成信息认证
			*/
			function saveNews(){
				var pName = $('#provenceSelect').children('option:selected').val(),
					province_id = $('#provenceSelect').children('option:selected').attr("dId"),
					cityName = $('#citySelect').children('option:selected').val(),
					city_id = $('#citySelect').children('option:selected').attr("dId");
				if(states == 1){
					layer.msg("实名认证审核中，请勿重复提交");
					return;
				}else if(states == 3){
					layer.msg("实名认证审核听过！");
					return;
				}
				var name = $('#name').val(),
					address = $('#address').val(),
					scale = $('#scale').val(),
					licence_poster = $('#logo').val();

				var basePicUrl = 'https://img.qikuai100.com/bg.png';
				if($.trim(name) == ''){
					layer.msg("请输入公司名称");
					return;
				}
				if($.trim(pName) == ''){
					layer.msg("请选择公司所在省");
					return;
				}
				if($.trim(cityName) == ''){
					layer.msg("请选择公司所在市");
					return;
				}
				if($.trim(address) == ''){
					layer.msg("请输入公司详细地址");
					return;
				}
				if($.trim(scale) == ''){
					layer.msg("请输入公司规模");
					return;
				}
				if ($("#logoPic").attr("src") == basePicUrl) {
		            layer.msg("请上传公司logo");
		            return;
		        }
				$.ajax({
					type: "POST",
					url: baseUrl + "api/company/add",
					data: {
						"uid": uid,
						"name": name,
						"province_id": province_id,
						"city_id": city_id,
						"address": address,
						"scale": scale,
						"licence_poster": $("#logoPic").attr("src")
					},
					success: function(result) {
						if(result.ret == 0){
							layer.msg("信息保存成功，请耐心等待审核！");
						}else{
							layer.msg(result.res_info);
						}
					}
				});
			}
			
		</script>

	</body>

</html>